<!DOCTYPE HTML>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>设置密码</title>
    <link rel="stylesheet" type="text/css" href="../../css/main.css" />
    <style>
        * {
            background: #e6e6e6;
        }

        .password {
            height: 50px;
            background: #fff;
            padding-left: 42px;
            line-height: 50px;
            border-bottom: 3px solid #e3e3e3;
            margin-top: 12px;
        }

        .in {
            margin-left: 37px;
            background: #fff;
            font-size: 16px;
        }

        .below {
            margin: 92px 27px 0px 27px;
            height: 38px;
            background: #ea5718;
            color: #fff;
            line-height: 38px;
            text-align: center;
            border-radius: 5px;
        }
    </style>

    <body>
        <div id="vm">
            <div class="big-box">
                <div class="verify">设置密码
                    <img src="../../image/login/back.png" class="back" onclick="closeWin()">
                </div>
                <div class="password">
                    密码<input type="possword" placeholder="请输入新密码" class="in" v-model="newpassword" v-on:input="addinput" />
                </div>
                <div class="below" v-on:click="submit()">
                    完成
                </div>
            </div>
        </div>
    </body>
    <script type="text/javascript" src="../../script/api.js"></script>
    <script type="text/javascript" src="../../script/vue.2.5.js"></script>
    <script type="text/javascript" src="../../script/zepto.js"></script>
    <script type="text/javascript" src="../../script/config.js"></script>
    <script type="text/javascript" src="../../script/rest.js"></script>
    <script type="text/javascript" src="../../script/login.js"></script>
    <script type="text/javascript" src="../../script/faskclick.js"></script>
    <script type="text/javascript">

    var vm = new Vue({
        el: '#vm',
        data: {
            newpassword: '',
            phonevalue:'',
            oldpassword:'',
        },
        created: function() {
            var _this = this;
            apiready = function() {
                _this.init();
                api.parseTapmode();
                var header = $api.byId('aui-header');
                $api.fixStatusBar(header);
                if ('addEventListener' in document) {
                    document.addEventListener('DOMContentLoaded', function() {
                        FastClick.attach(document.body);
                    }, false);
                }
            }
        },
        methods: {
            init: function() {
                var _this = this;
                _this.newpassword = '';
                _this.phonevalue =$api.getStorage('mobile');
                _this.oldpassword=$api.getStorage('password');
            },
            addinput:function(){
              var _this = this;
              _this.newpassword=_this.newpassword.replace(/[^\w\/]/ig,'');
              _this.newpassword=_this.newpassword.substr(0,16);
            },
            submit: function() {
                var _this = this;
                    if(M.password(_this.newpassword)){
                      new rest().get('modifyPassword').datae({
                          'mobile':_this.phonevalue,
                          'password': _this.oldpassword,
                          'repassword': _this.newpassword,
                      }).success(function(res) {
                          console.log(JSON.stringify(res.msg))
                          if (res.flag == 1) {
                              api.toast({
                                  msg: '修改成功',
                                  duration: 2000,
                                  location: 'middle'
                              });
                              $api.setStorage('password',_this.newpassword)
                          } else {
                            alert(res.msg)
                              api.toast({
                                  msg: res.msg,
                                  duration: 2000,
                                  location: 'middle'
                              });
                          }
                          setTimeout(function() {
                              api.closeWin();
                          }, 1000)
                      }).error(function(err) {
                          api.toast({
                              msg: err.msg,
                              duration: 2000,
                              location: 'middle'
                          });
                      }).run()
                    }


            },

        }
    })
    function closeWin(){
      api.closeWin();

    }
    </script>

</html>
